package com.xingge.socketio.listener;

import com.alibaba.fastjson.JSON;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.ConnectListener;

import lombok.extern.slf4j.Slf4j;

/**
 * @Title:  AppConnectListener.java
 * @Package com.xingge.socketio.listener
 * @Description: 用户连接监听器
 * @author: zhangwei
 * @date:   2022年8月6日
 * @time：	上午1:00:47
 * @version  v1.0
 * @Copyright: 2019 XingGe All rights reserved.
 */
@Slf4j
public class AppConnectListener implements ConnectListener {
	private SocketIOServer ioServer;
	
	public AppConnectListener(SocketIOServer ioServer) {
		this.ioServer = ioServer;
	}

	@Override
	public void onConnect(SocketIOClient client) {
		System.err.println(JSON.toJSONString(ioServer));
		log.info("{}({}) 接入连接 .",client.getRemoteAddress(), client.getSessionId());
		client.joinRoom("public");
		log.info("{} 加入 public 聊天室", client.getSessionId());
		client.leaveRoom("");
		log.info("{} 离开 '' 聊天室", client.getSessionId());
	}

}
